<?php


class User extends AppModel{
/*
      var $validate = array(
        'name' => array(
            'rule' => 'alphaNumeric',
            'required' => true,
            'AllowEmpty' => false,
            'message' => 'invalid last name'
        ),
        'surname' => array(
            'rule' => 'alphaNumeric',
            'required' => true,
            'AllowEmpty' => false,
            'message' => 'invalid first name'
        ),
        'password' => array(
            'rule' => array('minLength', '7'),
            'message' => 'Mimimum 7 characters long'
        ),
        'email' => 'email',
        'born' => array(
            'rule' => 'date',
            'message' => 'Enter a valid date',
            'allowEmpty' => true
        )
    );
*/
    public $hasMany = array(
        'UsersVideo' => array(
            'foreignKey' => 'users_id'
        )
    );
    
    
    public $hasOne = array(
        'UsersAdmin' => array(
            'foreignKey' => 'users_id'
        )
    );
    
    public $hasAndBelongsToMany = array(
        'Sport' => array(
            'foreignKey' => 'users_id',
            'associationForeignKey' => 'sports_id',
            'joinTable' => 'users_sports'
        )
    );
    
    public function getUser($type, $options = array()){
        $data = $this->find($type, $options);
        
        
        if (!empty($data)){
            if ($type=='first'){
                if (empty($data['UsersAdmin']['users_id']))
                    $data['UsersAdmin'] = false;          
            }
            else{
                foreach ($data as $key => $d){        
                    if (empty($d['UsersAdmin']['users_id']))
                        $data[$key]['UsersAdmin'] = false;     

                }
            }
        }
        return $data;
    }
    
    public function getUserById($id, $options = array()){
        $data = $this->getUser('first', array('conditions' => array('User.id' => $id)));
        return $data;
    }
}


?>
